package com.atguigu.gmall.order.listener;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.common.config.rabbitMq.MqService;
import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.mq.logistic.OrderLogisticMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.nio.channels.Channel;

@Slf4j
@Service
public class OrderLogisticListener {
    @Autowired
    MqService  mqService;
    @RabbitListener(bindings = {@QueueBinding(
            value = @Queue(value = MqConst.ORDER_LOGISTIC_QUEUE,durable = "true",
                    exclusive = "false",autoDelete = "false"),
            exchange=@Exchange(value =MqConst.ORDER_EVENT_EXCHANGE,
                            durable = "true",
                           autoDelete = "false",
                           type = "topic"),
            key = MqConst.ORDER_LOGISTIC_RK
    )})
    public  void listen(Message  message, Channel channel){
        String content=new String(message.getBody());
        OrderLogisticMsg msg = JSON.parseObject(content, OrderLogisticMsg.class);
        log.info("准备电子面单",msg.getOrderId());
        //TODO 生成电子面单数据
    }


}
